package com.feihao.demo01DateJDK8;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class ParseFormatTest {
    public static void main(String[] args) {
        LocalDateTime lo = LocalDateTime.now();
        System.out.println(lo);

        //格式化：
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = lo.format(dtf);
        System.out.println(format);


        //解析：
        String dateStr = "2022-10-02 08:08:08";
        //定义模板：
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(dateStr, dtf2);
        System.out.println(parse);
    }
}
